package com.dcms.web.controller;

import com.dcms.power.annotation.ArchivesLog;
import com.dcms.admin.controller.BaseController;
import com.dcms.util.ResultBean;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Controller
public class TestController extends BaseController{


    @RequestMapping("test")
    public String test(HttpServletRequest request){
        request.setAttribute("test","测试");
        return "test";
    }

    @ArchivesLog(message = "jsonp请求")
    @RequestMapping( value = "test/jsonp")
    public void testJSONP(String param, HttpServletResponse response) throws IOException{
        String callback = (String)request.getParameter("callback");
        String jsonData = "{\"id\":\"3\", \"name\":\"zhangsan\", \"telephone\":\"13612345678\"}";
        String retStr = callback + "(" + jsonData + ")";
        response.getWriter().print(retStr);
    }

    @ArchivesLog(message = "jquery.jsonp请求")
    @RequestMapping( value = "test/json")
    @ResponseBody
    public ResultBean testJSONP(String param){
        return new ResultBean(101, "success", param);
    }
}